#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int dp[30050];  int v[25];  int w[25];
int n;      int m;

int main(){
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        scanf("%d%d",&v[i],&w[i]);
        w[i] *= v[i];
    }
    for(int i = 1; i <= m; i++){
        for(int j = n; j >= v[i]; j--){
            dp[j] = max ( dp[j], dp[j - v[i]] + w[i] );
        }
    }
    cout<< dp[n] << endl;
    return 0; 
}